﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
using TrainingWorkshop.IDAL;

namespace TrainingWorkshop.DAL_SQL
{
    public class LevelRepository_Sql : ILevelRepository
    {
        private SqlConnection sqlConnection;

        public LevelRepository_Sql(SqlConnection sqlConnection)
        {
            // TODO: Complete member initialization
            this.sqlConnection = sqlConnection;
        }


        public List<Model.Level> SelectAll()
        {
            List<Model.Level> levelList = new List<Model.Level>();


                sqlConnection.Open();
                //get table
                string selectStatement = "select * from Level" ;
                SqlDataAdapter da = new SqlDataAdapter(selectStatement, sqlConnection);
                DataTable dt = new DataTable();
                da.Fill(dt);
                //convert to list
                foreach (DataRow row in dt.Rows)
                {
                    Model.Level level = new Model.Level();
                    level.LevelId = Convert.ToInt32(row[0]);
                    level.LevelName = row[1].ToString().Trim();
                    levelList.Add(level);
                }
                sqlConnection.Close();
            return levelList;
        }
    }
    
}
